home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2007 September
/
PCWorld_2007-09_cd.bin
/
system
/
ntfs
/
ntfsundelete.exe
/
{app}
/
ntpath.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2007-02-05
|
12KB
|
439 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.4)
'''Common pathname manipulations, WindowsNT/95 version.
Instead of importing this module directly, import os and refer to this
module as os.path.
'''
import os
import stat
import sys
__all__ = [
'normcase',
'isabs',
'join',
'splitdrive',
'split',
'splitext',
'basename',
'dirname',
'commonprefix',
'getsize',
'getmtime',
'getatime',
'getctime',
'islink',
'exists',
'isdir',
'isfile',
'ismount',
'walk',
'expanduser',
'expandvars',
'normpath',
'abspath',
'splitunc',
'curdir',
'pardir',
'sep',
'pathsep',
'defpath',
'altsep',
'extsep',
'devnull',
'realpath',
'supports_unicode_filenames']
curdir = '.'
pardir = '..'
extsep = '.'
sep = '\\'
pathsep = ';'
altsep = '/'
defpath = '.;C:\\bin'
if 'ce' in sys.builtin_module_names:
defpath = '\\Windows'
elif 'os2' in sys.builtin_module_names:
altsep = '/'
devnull = 'nul'
def normcase(s):
'''Normalize case of pathname.
Makes all characters lowercase and all slashes into backslashes.'''
return s.replace('/', '\\').lower()
def isabs(s):
'''Test whether a path is absolute'''
s = splitdrive(s)[1]
if s != '':
pass
return s[:1] in '/\\'
def join(a, *p):
'''Join two or more pathname components, inserting "\\" as needed'''
path = a
for b in p:
b_wins = 0
if path == '':
b_wins = 1
elif isabs(b):
if path[1:2] != ':' or b[1:2] == ':':
b_wins = 1
elif (len(path) > 3 or len(path) == 3) and path[-1] not in '/\\':
b_wins = 1
if b_wins:
path = b
continue
None if not len(path) > 0 else b[0] in '/\\'
None if path[-1] == ':' else b[0] in '/\\'
path += '\\'
return path
def splitdrive(p):
'''Split a pathname into drive and path specifiers. Returns a 2-tuple
"(drive,path)"; either part may be empty'''
if p[1:2] == ':':
return (p[0:2], p[2:])
return ('', p)
def splitunc(p):
"""Split a pathname into UNC mount point and relative path specifiers.
Return a 2-tuple (unc, rest); either part may be empty.
If unc is not empty, it has the form '//host/mount' (or similar
using backslashes). unc+rest is always the input path.
Paths containing drive letters never have an UNC part.
"""
if p[1:2] == ':':
return ('', p)
firstTwo = p[0:2]
if firstTwo == '//' or firstTwo == '\\\\':
normp = normcase(p)
index = normp.find('\\', 2)
if index == -1:
return ('', p)
index = normp.find('\\', index + 1)
if index == -1:
index = len(p)
return (p[:index], p[index:])
return ('', p)
def split(p):
'''Split a pathname.
Return tuple (head, tail) where tail is everything after the final slash.
Either part may be empty.'''
(d, p) = splitdrive(p)
i = len(p)
while i and p[i - 1] not in '/\\':
i = i - 1
head = p[:i]
tail = p[i:]
head2 = head
while head2 and head2[-1] in '/\\':
head2 = head2[:-1]
if not head2:
pass
head = head
return (d + head, tail)
def splitext(p):
'''Split the extension from a pathname.
Extension is everything from the last dot to the end.
Return (root, ext), either part may be empty.'''
i = p.rfind('.')
if i <= max(p.rfind('/'), p.rfind('\\')):
return (p, '')
else:
return (p[:i], p[i:])
def basename(p):
'''Returns the final component of a pathname'''
return split(p)[1]
def dirname(p):
'''Returns the directory component of a pathname'''
return split(p)[0]
def commonprefix(m):
'''Given a list of pathnames, returns the longest common leading component'''
if not m:
return ''
prefix = m[0]
for item in m:
for i in range(len(prefix)):
if prefix[:i + 1] != item[:i + 1]:
prefix = prefix[:i]
if i == 0:
return ''
break
continue
return prefix
def getsize(filename):
'''Return the size of a file, reported by os.stat()'''
return os.stat(filename).st_size
def getmtime(filename):
'''Return the last modification time of a file, reported by os.stat()'''
return os.stat(filename).st_mtime
def getatime(filename):
'''Return the last access time of a file, reported by os.stat()'''
return os.stat(filename).st_atime
def getctime(filename):
'''Return the creation time of a file, reported by os.stat().'''
return os.stat(filename).st_ctime
def islink(path):
'''Test for symbolic link. On WindowsNT/95 always returns false'''
return False
def exists(path):
'''Test whether a path exists'''
try:
st = os.stat(path)
except os.error:
return False
return True
lexists = exists
def isdir(path):
'''Test whether a path is a directory'''
try:
st = os.stat(path)
except os.error:
return False
return stat.S_ISDIR(st.st_mode)
def isfile(path):
'''Test whether a path is a regular file'''
try:
st = os.stat(path)
except os.error:
return False
return stat.S_ISREG(st.st_mode)
def ismount(path):
'''Test whether a path is a mount point (defined as root of drive)'''
(unc, rest) = splitunc(path)
if unc:
return rest in ('', '/', '\\')
p = splitdrive(path)[1]
if len(p) == 1:
pass
return p[0] in '/\\'
def walk(top, func, arg):
"""Directory tree walk with callback function.
For each directory in the directory tree rooted at top (including top
itself, but excluding '.' and '..'), call func(arg, dirname, fnames).
dirname is the name of the directory, and fnames a list of the names of
the files and subdirectories in dirname (excluding '.' and '..'). func
may modify the fnames list in-place (e.g. via del or slice assignment),
and walk will only recurse into the subdirectories whose names remain in
fnames; this can be used to implement a filter, or to impose a specific
order of visiting. No semantics are defined for, or required of, arg,
beyond that arg is always passed to func. It can be used, e.g., to pass
a filename pattern, or a mutable object designed to accumulate
statistics. Passing None for arg is common."""
try:
names = os.listdir(top)
except os.error:
return None
func(arg, top, names)
exceptions = ('.', '..')
for name in names:
if name not in exceptions:
name = join(top, name)
if isdir(name):
walk(name, func, arg)
isdir(name)
def expanduser(path):
'''Expand ~ and ~user constructs.
If user or $HOME is unknown, do nothing.'''
if path[:1] != '~':
return path
i = 1
n = len(path)
while i < n and path[i] not in '/\\':
i = i + 1
if i == 1:
if 'HOME' in os.environ:
userhome = os.environ['HOME']
elif 'HOMEPATH' not in os.environ:
return path
else:
try:
drive = os.environ['HOMEDRIVE']
except KeyError:
drive = ''
userhome = join(drive, os.environ['HOMEPATH'])
else:
return path
return userhome + path[i:]
def expandvars(path):
'''Expand shell variables of form $var and ${var}.
Unknown variables are left unchanged.'''
if '$' not in path:
return path
import string as string
varchars = string.ascii_letters + string.digits + '_-'
res = ''
index = 0
pathlen = len(path)
while index < pathlen:
c = path[index]
if c == "'":
path = path[index + 1:]
pathlen = len(path)
try:
index = path.index("'")
res = res + "'" + path[:index + 1]
except ValueError:
res = res + path
index = pathlen - 1
except:
None<EXCEPTION MATCH>ValueError
None<EXCEPTION MATCH>ValueError
if c == '$':
None if path[index + 1:index + 2] == '$' else None<EXCEPTION MATCH>ValueError
var = ''
index = index + 1
c = path[index:index + 1]
while c != '' and c in varchars:
var = var + c
index = index + 1
c = path[index:index + 1]
if var in os.environ:
res = res + os.environ[var]
if c != '':
res = res + c
else:
res = res + c
index = index + 1
return res
def normpath(path):
'''Normalize path, eliminating double slashes, etc.'''
path = path.replace('/', '\\')
(prefix, path) = splitdrive(path)
if prefix == '':
while path[:1] == '\\':
prefix = prefix + '\\'
path = path[1:]
elif path.startswith('\\'):
prefix = prefix + '\\'
path = path.lstrip('\\')
comps = path.split('\\')
i = 0
while i < len(comps):
None if comps[i] in ('.', '') else prefix.endswith('\\')
i += 1
if not prefix and not comps:
comps.append('.')
return prefix + '\\'.join(comps)
def abspath(path):
'''Return the absolute version of a path'''
global abspath
try:
_getfullpathname = _getfullpathname
import nt
except ImportError:
def _abspath(path):
if not isabs(path):
path = join(os.getcwd(), path)
return normpath(path)
abspath = _abspath
return _abspath(path)
if path:
try:
path = _getfullpathname(path)
except WindowsError:
pass
except:
None<EXCEPTION MATCH>WindowsError
None<EXCEPTION MATCH>WindowsError
path = os.getcwd()
return normpath(path)
realpath = abspath
if hasattr(sys, 'getwindowsversion'):
pass
supports_unicode_filenames = sys.getwindowsversion()[3] >= 2